﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model_SSResourceManager;

namespace Presenter_SSResourceManager
{
    public class PresenterLogin
    {
        private readonly IViewLogin _viewLogin;
        private readonly ModelsManager _mModel;

        public PresenterLogin(IViewLogin view)
        {
            _viewLogin = view;
            _mModel = ModelInstanse.Get();

        }

        public void LoginUser()
        {
            var userName = _viewLogin.GetUserName();
            var password = _viewLogin.GetPassword();
            var userId = _mModel.userModel.Login(userName, password);
            var userRole = _mModel.userModel.GetUserRole(userId);
            if (userId != Guid.Empty)
            {
                _viewLogin.PerformLogging(userName);
                _viewLogin.SetUserId(userId);
                _viewLogin.SetUserRole(userName, userRole);
            }
            else
            {
                _viewLogin.Filure("Your login attempt was not successful. Please try again.");
            }
        }

        public string GetUserRole(Guid userId)
        {
            return _mModel.userModel.GetUserRole(userId);
        }
    }
}
